#include <iostream>

using namespace std;

int RSQ(int* B, int k){
    int result = 0;
    
    while (k >= 0) {
        result += B[k];
        k = (k & (k + 1)) - 1;
    }
    
    return result;
}

void updateRSQ(int* A, int* B, int n, int indx, int val) {
    A[indx] += val;
    
    while (indx < n) {
        B[indx] += val;
        indx = indx | (indx + 1);
    }
}

int RSQ(int* B, int a, int b){
    return RSQ(B, b) - RSQ(B, a - 1);
}

int main() {
    int n = 0;
    cin>>n;
    
    int* A = new int[n];
    int* B = new int[n];
    
	for (int i = 0; i < n; ++i) { B[i] = 0; }
	
    int c;
    for (int i = 0; i < n; ++i) {
        cin>>c;
        A[i] = 0;
        updateRSQ(A, B, n, i, c);
    }

    int a = 0, b = 0;
    while (a >= 0 && b >= 0) {
        cin>>a>>b;
        cout<<RSQ(B, a, b)<<endl;  
    }
    
    delete[] A;
    delete[] B;
    return 0;
}
